<template>
  <div class="main" v-color="'bgkImg'">
    <dz-nav :is-back="true" :back-url="'/my'">
      <template #center>
        <b v-color><qq>Invite</qq></b>
      </template>
    </dz-nav>
    <div class="box-center">
      <div class="qrcode">
        <canvas style="width: 220px;height: 220px" ref="qrcodeCanvas"></canvas>
      </div>
    </div>
    <div class="box-nav">
      <div class="btn-nav">
        <div class="left">
          <p class="title"><qq>Invitation</qq></p>
          <p class="link">{{ form.invitationCode }}</p>
        </div>
        <div class="right">
          <img @click="oncopy(form.invitationCode)" src="@/assets/images/btn-link.png" alt="">
        </div>
      </div>
      <div class="btn-nav url">
        <div class="left">
          <p class="title"><qq>InvitationUrl</qq></p>
          <div class="link">{{form.invitationLink}}</div>
        </div>
        <div class="right">
          <img @click="oncopy(form.invitationLink)" src="@/assets/images/btn-link.png" alt="">
        </div>
      </div>
      <div class="submit">
        <img src="@/assets/images/Invitefriends.png" @click="oncopy(form.invitationLink)" alt="">  <qq>SendInvitation</qq>
      </div>
      <div class="submit">
        <img src="@/assets/images/Becomevip.png" v-routers="{path:'/buy'}" alt="">  <qq>BecomeVip</qq>
      </div>
      <div class="submit">
        <img src="@/assets/images/Getrewards.png" alt="" v-routers="{path:'/recharge'}">  <qq>GetRewards</qq>
      </div>
    </div>
    <dz-safe></dz-safe>
  </div>
</template>

<script>
  import {invitation} from "@/api/apiFox";
  import QRCode from "qrcode";
  import {Toast} from "vant";

  export default {
    data(){
      return{
        form:{}
      }
    },
    methods:{
      getList(){
        invitation().then(res=>{
          console.log(res)
          this.form = res
          this.generateQRCode()
        }).catch(err=>{})
      },
      generateQRCode() {
        const canvas = this.$refs.qrcodeCanvas
        QRCode.toCanvas(canvas, this.form.invitationLink, error => {
          if (error) console.error(error)
        })
      },
      oncopy(code){
        this.$copyText(code).then(
            e=>{
              Toast({
                position:'center',
                message:this.$t('Success')
              })
            },
            e=>{
              console.log('error：', e);
            }
        )
      },
    },
    mounted() {
      this.getList()
    }
  }
</script>


<style scoped lang="scss">
.main{
  width: 100%;
  min-height: 100vh;
  .box-center{
    width: 100%;
    height: 266px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 28px;
    .qrcode{
      width: 266px;
      height: 266px;
      background: #FFFFFF;
      border-radius: 20px 20px 20px 20px;
      border-image: linear-gradient(39deg, rgba(0, 0, 0, 1), rgba(0, 0, 0, 0)) 1 1;
      background-image: url("@/assets/images/qrcode.png");
      background-size: cover;
      display: flex;
      justify-content: center;
      align-items: center;
      img{
        width: 220px;
        height: 220px;
        object-fit: cover;
        border-radius: 10px;
      }
      canvas{
        width: 220px;
        height: 220px;
        object-fit: cover;
        border-radius: 10px;
      }
    }
  }
  .box-nav{
    width: 100%;
    padding: 16px;
    box-sizing: border-box;
    .btn-nav{
      width: 343px;
      height: 58px;
      background: #FFFFFF;
      box-shadow: 0px 4px 4px 0px rgba(89,67,221,0.25);
      border-radius: 60px 60px 60px 60px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 12px 20px;
      box-sizing: border-box;
      margin-bottom: 10px;
      .left{
        width: 250px;
        min-height: 50px;
        .title{
          font-weight: 400;
          font-size: 14px;
          color: #242B35;
          margin-top: 5px;
        }
        .link{
          width: 250px;
          overflow: scroll;
          height: 30px;
          font-weight: bold;
          font-size: 12px;
          color: #533DF1;
        }
      }
      .right{
        width: 50px;
        height: 58px;
        display: flex;
        justify-content: center;
        align-items: center;
        img{
          width: 28px;
          height: 28px;
          object-fit: cover;
        }
      }
    }
    .url{
      height: 68px;
      padding: 12px 20px;
    }
    .submit{
      width: 343px;
      height: 62px;
      background: linear-gradient( 90deg, #973DF1 0%, #5134C3 100%);
      box-shadow: 0px 4px 4px 0px rgba(92,18,187,0.25), inset 0px 4px 4px 0px rgba(249,249,249,0.25);
      border-radius: 30px 30px 30px 30px;
      font-weight: bold;
      font-size: 16px;
      color: #FFFFFF;
      display: flex;
      justify-content: center;
      align-items: center;
      margin-top: 10px;
      img{
        width: 50px;
        height: 50px;
        object-fit: cover;
      }
    }
  }
}
</style>